package sam.learn.biz.role.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import sam.learn.biz.role.repo.entity.UserRoleRelation;
import sam.learn.biz.role.repo.mapper.UserRoleRelationMapper;
import sam.learn.biz.role.service.UserRoleRelationService;

@Service
public class UserRoleRelationServiceImpl implements UserRoleRelationService {

    @Autowired
    private UserRoleRelationMapper userRoleRelationMapper;

    @Override
    @DS("")
    @Cacheable(value = "user-center:user-role-info", key = "#userId")
    public UserRoleRelation getUserRoleRelationBy(String userId) {
        LambdaQueryWrapper<UserRoleRelation> lambdaQueryWrapper = new LambdaQueryWrapper<>(UserRoleRelation.class);
        lambdaQueryWrapper.eq(UserRoleRelation::getUserId, userId);
        return userRoleRelationMapper.selectOne(lambdaQueryWrapper);
    }
}
